package com.shuang.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.shuang.mapper.DbGoodsParamMapper;
import com.shuang.pojo.DbGoodsParam;
import com.shuang.pojo.DbGoodsParamExample;
import com.shuang.pojo.DbGoodsParamExample.Criteria;
import com.shuang.service.DbGoodsFormatParamService;
@Service("dbGoodsFormatParamService")
public class DbGoodsFormatParamServicImpl implements DbGoodsFormatParamService {

	@Resource(name="dbGoodsParamMapper")
	private DbGoodsParamMapper dbGoodsParamMapper;
	
	@Override
	public Map<String, Object> getFormatInfoById(Long gId) {
		 DbGoodsParamExample example = new DbGoodsParamExample();
		 Criteria criteria = example.createCriteria();
		 criteria.andGIdEqualTo(gId);
		List<DbGoodsParam> result = dbGoodsParamMapper.selectByExampleWithBLOBs(example);
		Map<String, Object> map=new HashMap<String, Object>();
		
		if(result!=null&&result.size()>0){
			map.put("status", 200);
			map.put("data", result.get(0));
		}else{
			map.put("status", 404);
			map.put("data", "未找到指定id的规格信息");
		}
		
		return map;
	}

	@Override
	public Map<String, Object> updateFormatInfoById(Long gId, String formatParam) {
		DbGoodsParam record = new DbGoodsParam();
		record.setGpUpdateTime(new Date());
		record.setGpParamData(formatParam);
		 DbGoodsParamExample example = new DbGoodsParamExample();
		 Criteria criteria = example.createCriteria();
		 criteria.andGIdEqualTo(gId);
		 Map<String, Object> map=new HashMap<String, Object>();
		int result=dbGoodsParamMapper.updateByExampleSelective(record, example);
		if(result>0){
			map.put("status", 200);
		}else{
			map.put("status", 404);
			map.put("data", "更新操作失败");
		}
		return map;
	}

}
